-
Notifications
You must be signed in to change notification settings - Fork 7.4k
kernel: add k_clock api: remove posix dependency from iso c time #90096
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
kernel: add k_clock api: remove posix dependency from iso c time #90096
Conversation
a403e85
to
83dc940
Compare
db7b057
to
fe430cf
Compare
I'd like to get those in better shape before marking this ready for review. |
swap the relative position of the __cplusplus closing bracket and the doxygen end-group comment. Signed-off-by: Chris Friedt <[email protected]>
fe430cf
to
9a4203b
Compare
Add a number of utility functions for manipulating struct timespec. * timespec_add() * timespec_compare() * timespec_equal() * timespec_is_valid() * timespec_negate() * timespec_normalize() * timespec_sub() * timespec_from_timeout() * timespec_to_timeout() If the `__builtin_add_overflow()` function is available, then the API is mostly branchless, which should provide decent performance on systems with an instruction cache and branch prediction. Otherwise, manually written alternatives exist that are also perhaps more readable. The two functions at the end convert time durations between representation as `struct timespec` and `k_timeout_t`. Signed-off-by: Chris Friedt <[email protected]>
Add a timespec util testsuite. This should have reasonably high enough coverage to be useful. I would have preferred to add this as an architecture-independent unit test (for the unit_testing platform) under tests/unit/timeutil but there is an inconsistency about the size of time_t on the unit_testing and native_sim/native platforms. On every other platform supported by Zephyr, time_t is 64-bits. However, on those platforms, time_t is only 32-bits. Signed-off-by: Chris Friedt <[email protected]>
Add documentation in the timeutil group for recently added functions for validating, comparing, and manipulating `struct timespec` objects as well as functions for converting between representation of time durations as either `struct timespec` or `k_timeout_t`. Signed-off-by: Chris Friedt <[email protected]>
Use the newly added timespec util functions to manipulate and compare timespec structures with overflow detection. Signed-off-by: Chris Friedt <[email protected]>
9a4203b
to
5078a47
Compare
Add the k_clock API, comprised of: * k_clock_gettime() * k_clock_settime() * k_clock_nanosleep() along with the constants * K_CLOCK_REALTIME * K_CLOCK_MONOTONIC * K_TIMER_ABSTIME The primary motivation for this API is so that libc and other libraries have a familiar-enough API to reach to when POSIX is not available, since POSIX is optional in Zephyr. By adding this API to the Zephyr kernel, we also eliminate dependency cycles between libc and posix, as the kernel is a mutual dependency. Signed-off-by: Chris Friedt <[email protected]>
Remove POSIX clock_gettime() from the common libc time implementation, since POSIX should not be a dependency for ISO C. Signed-off-by: Chris Friedt <[email protected]>
Use the implementation of time() from the common libc, since there it no longer pulls in POSIX. Use is implied for minimal, newlib, and picolibc, and selected for IAR. Signed-off-by: Chris Friedt <[email protected]>
Reduce the dependency on POSIX by taking advantage of the newly added k_clock_nanosleep(). Signed-off-by: Chris Friedt <[email protected]>
Use `timespec_from_timeout(K_MSEC(msec), &ts)` instead of leaning on lazily-crafted timespecs with invalid tv_nsec fields. Signed-off-by: Chris Friedt <[email protected]>
Presumably the time testsuite was separate from the c library set of testsuites because it had a depedency on POSIX. Since that dependency no longer exists, colocate the time testsuite with the other c library testsuites. Signed-off-by: Chris Friedt <[email protected]>
Use the newly added k_clock API in the kernel for * clock_gettime() * clock_settime() * clock_nanosleep() and nanosleep() * gettimeofday() Signed-off-by: Chris Friedt <[email protected]>
The ISO C function time() should not depend on POSIX and this was corrected recently via the common libc time() implementation. Remove this dependency from the network subsystem where it has been unduly needed for some time. Similarly, XSI_SINGLE_PROCESS was a dependency for time() via picolibc, because the time() implementation in picolibc relies on the POSIX gettimeofday() call. However, since Zephyr's common libc time() implementation no longer depends on that, it can be removed as a dependency in the network subsystem as well. Signed-off-by: Chris Friedt <[email protected]>
Remove POSIX_TIMERS and XSI_SINGLE_PROCESS dependencies from the aws cloud sample and the lwm2m client sample, as they are no longer required. Signed-off-by: Chris Friedt <[email protected]>
5078a47
to
730558c
Compare
|
Question ... would the proposed k_clock APIs be better served somewhere under /subsys as something like sys_clock APIs? I am wary of them being placed under /kernel. |
|
Should be merged after #90060